cmake_minimum_required(VERSION 3.28.3)
project(ns3test)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#set(NS3_INSTALL_DIR "$ENV{HOME}/.local")
#set(NS3_PYTHON_BINDINGS_DIR "/home/gorio/ns3_env/lib/python3.12/site-packages")
# 让 pkg-config 看到你用户目录的 ns-3 .pc 文件
set(ENV{PKG_CONFIG_PATH} "$ENV{HOME}/.local/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:$ENV{PKG_CONFIG_PATH}")
# 让 pkg-config 也使用 CMAKE_PREFIX_PATH
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
# 把 ~/.local 也加入 CMake 的前缀路径（有些系统和模块会用到）
list(PREPEND CMAKE_PREFIX_PATH "$ENV{HOME}/.local")


find_package(PkgConfig REQUIRED)
pkg_check_modules(NS3CORE    REQUIRED IMPORTED_TARGET ns3-core)
pkg_check_modules(NS3NETWORK REQUIRED IMPORTED_TARGET ns3-network)
pkg_check_modules(NS3INET    REQUIRED IMPORTED_TARGET ns3-internet)
pkg_check_modules(NS3APPS   REQUIRED IMPORTED_TARGET ns3-applications)
pkg_check_modules(NS3WIFI   REQUIRED IMPORTED_TARGET ns3-wifi)

include_directories(
        include
#        ${NS3_INSTALL_DIR}/include/ns3
)

# 添加库文件搜索路径
#link_directories(${NS3_INSTALL_DIR}/lib)


add_library(duavsim SHARED
        src/duavsim.cpp
)
target_include_directories(duavsim
        PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${NS3_INCLUDE_DIRS}
)
target_link_libraries(duavsim
        PUBLIC
        ${NS3_LDFLAGS}
)

# 避免不同编译器下隐藏符号；给 cppyy 用时更稳
set_target_properties(duavsim PROPERTIES
        CXX_VISIBILITY_PRESET default
        VISIBILITY_INLINES_HIDDEN OFF
)

# 方便安装/引用
install(TARGETS duavsim
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
)
install(FILES include/duavsim.h DESTINATION include)

add_executable(ns3test main.cpp
        include/duavsim.h
        src/duavsim.cpp)


## 链接 NS3 核心库（根据实际模块调整）
target_link_libraries(ns3test
        PRIVATE
        PkgConfig::NS3CORE
        PkgConfig::NS3NETWORK
        PkgConfig::NS3INET
        PkgConfig::NS3APPS  # 若上面启用了再解开
        PkgConfig::NS3WIFI
)